﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;

//using Roslyn.Services;
//using Roslyn.Compilers.CSharp;
//using Roslyn.Compilers.Common;

//using King.Reflection;
//using King.Extensions;
//using System.Threading.Tasks;
//using Roslyn.Compilers;

//namespace King.CSharp.Parser {

//    public abstract class WorkspaceObject { 
    
//    }

//    public sealed class WorkspaceLoader {

//        private static Dictionary<object, object> s_cache = new Dictionary<object, object>();

//        public static WorkspaceInfo Load(string path, string configuration = null, string platform = null) {
//            var result = Workspace.LoadSolution(path, configuration, platform);
//            var workspace = Get<WorkspaceInfo>(result);
//            return workspace;
//        }

//        private static T Get<T>(object o) {
//            var result = s_cache.GetValueOrDefault(o);
//            if (result == null)
//                s_cache[o] = result = typeof(T).Activate(o);
//            return (T)result;
//        }
//    }

//    public sealed class WorkspaceInfo {
//        public static IWorkspace LoadSolution(string solutionFileName, string configuration = "Debug", string platform = "AnyCPU");
//        public static IWorkspace LoadStandAloneProject(string projectFileName, string configuration = "Debug", string platform = "AnyCPU", string language = null);

//        public virtual ISolution CurrentInProgressSolution { get; }
//        public virtual ISolution CurrentSolution { get; }
//        public virtual bool EditInProgress { get; }
//        public IEnumerable<IWorkspaceListener> Listeners { get; }
//        public virtual IWorkspaceVersion Version { get; }

//        public virtual Task<bool> ApplyChangesAsync(ISolution oldSolution, ISolution newSolution, CancellationToken cancellationToken = null);

//        public virtual Task<ProjectId> AddProjectAsync(string projectName, string language);

//        public virtual ISolutionEdit CreateEdit(string description);

//        public virtual DocumentId GetDocumentId(ITextContainer textContainer);

//        public bool TryGetDocument(IText text, out IDocument document);

//        public void AddListener(IWorkspaceListener listener);
//        public void RemoveListener(IWorkspaceListener listener);

//        public bool TryGetDocumentFromInProgressSolution(IText text, out IDocument document);
//    }

//    public sealed class SolutionInfo : WorkspaceObject {
//        public virtual Task RemoveProjectAsync(ProjectId projectId);
//    }

//    public sealed class ProjectInfo : WorkspaceObject {
//        public virtual Task<DocumentId> AddDocumentAsync(
//            ProjectId projectId, 
//            IEnumerable<string> folders, 
//            string preferredDocumentName, 
//            IText text = null, 
//            SourceCodeKind sourceCodeKind = SourceCodeKind.Regular);

//        public virtual Task UpdateCompilationOptionsAsync(ProjectId projectId, ICompilationOptions options);

//        public virtual Task AddMetadataReferenceAsync(ProjectId fromProjectId, MetadataReference toMetadata);
//        public virtual Task RemoveMetadataReferenceAsync(ProjectId fromProjectId, MetadataReference toMetadata);

//        public virtual Task AddProjectReferenceAsync(ProjectId fromProjectId, ProjectId toProjectId);
//        public virtual Task RemoveProjectReferenceAsync(ProjectId fromProjectId, ProjectId toProjectId);
//    }

//    public sealed class DocumentInfo : WorkspaceObject {
//        public virtual Task OpenDocumentAsync(DocumentId documentId);
//        public virtual Task RemoveDocumentAsync(DocumentId documentId);
//        public virtual Task UpdateDocumentAsync(DocumentId documentId, IText newText);
//        public virtual Task UpdateParseOptionsAsync(DocumentId documentId, IParseOptions options);
//        public virtual Task CloseDocumentAsync(DocumentId documentId);
//    }
//}
